#!/usr/bin/python

###############################
## A base function for plots ##
###############################

#######################################################      
## Set PyRoot Environment and PlotConfig Path first ###
#######################################################
import sys
ROOTSYS = '/afs/atlas.umich.edu/opt/root/lib'
sys.path.append(ROOTSYS)
PlotConfig='../'
PlotConfig2='.'
sys.path.append(PlotConfig)
sys.path.append(PlotConfig2)

#####################
## Import Module  ###
#####################
import array
import os
import glob
from math import sqrt,fabs,sin
from ROOT import TFile,TTree,TChain,TBranch,TH1,TH1F,TList
from ROOT import TLorentzVector
from ROOT import THStack,TCanvas,TLegend,TColor,TPaveText
from ROOT import gStyle,gDirectory

####################
## Import Template #
####################
from plot_template import plot_template
from plot_template_combined import plot_template_combined

###############
## Plotting ###
###############
RatioSize=-0.2
RatioErr=1
RatioMin,RatioMax=0.5,1.5
RatioAdj=-1

ShowMCErr=1
MCErreeee=0.062
MCErreemm=0.052
MCErrmmee=0.052
MCErrmmmm=0.046
MCErr4l=0.052

plot_config='plot_configure'

histoDir='ZpT'

#ATLAS='ATLAS For Approval'
ATLAS=''
figFormat='all'

yscale=2

####### TrigMatch, PtZ1
Xmin, Xmax=0, 300
Rebin=20
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_TrigMatch_PtZ1'
hxt='p_{T}^{Z1},eeee [GeV]'
MCErr=MCErreeee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_TrigMatch_PtZ1'
hxt='p_{T}^{Z1},ee#mu#mu [GeV]'
MCErr=MCErreemm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_TrigMatch_PtZ1'
hxt='p_{T}^{Z1},#mu#muee [GeV]'
MCErr=MCErrmmee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_TrigMatch_PtZ1'
hxt='p_{T}^{Z1},#mu#mu#mu#mu [GeV]'
MCErr=MCErrmmmm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_TrigMatch_PtZ1'
hxt='p_{T}^{Z1} [GeV]'
MCErr=MCErr4l
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

####### TrigMatch, PtZ2
Xmin, Xmax=0, 300
Rebin=20
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_TrigMatch_PtZ2'
hxt='p_{T}^{Z2},eeee [GeV]'
MCErr=MCErreeee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_TrigMatch_PtZ2'
hxt='p_{T}^{Z2},ee#mu#mu [GeV]'
MCErr=MCErreemm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_TrigMatch_PtZ2'
hxt='p_{T}^{Z2},#mu#muee [GeV]'
MCErr=MCErrmmee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_TrigMatch_PtZ2'
hxt='p_{T}^{Z2},#mu#mu#mu#mu [GeV]'
MCErr=MCErrmmmm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_TrigMatch_PtZ2'
hxt='p_{T}^{Z2} [GeV]'
MCErr=MCErr4l
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

####### TrigMatch, PtZZ
Xmin, Xmax=0, 300
Rebin=20
Events=str('Events / %dGeV' % Rebin)
hname=histoDir+'_eeee_TrigMatch_PtZZ'
hxt='p_{T}^{ZZ},eeee [GeV]'
MCErr=MCErreeee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_eemm_TrigMatch_PtZZ'
hxt='p_{T}^{ZZ},ee#mu#mu [GeV]'
MCErr=MCErreemm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmee_TrigMatch_PtZZ'
hxt='p_{T}^{ZZ},#mu#muee [GeV]'
MCErr=MCErrmmee
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_mmmm_TrigMatch_PtZZ'
hxt='p_{T}&{ZZ},#mu#mu#mu#mu [GeV]'
MCErr=MCErrmmmm
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)
hname=histoDir+'_incl_TrigMatch_PtZZ'
hxt='p_{T}^{ZZ} [GeV]'
MCErr=MCErr4l
plot_template(histodir=histoDir,hname=hname,configfile=plot_config,hxt=hxt,hyt=Events,hrebin=Rebin,xmin=Xmin,xmax=Xmax,yscale=yscale,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,show_mcerr=ShowMCErr,percent_mcerr=MCErr,showATLAS=ATLAS,figformat=figFormat)

